﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace GSManager
{
    public class PhieuBanHang
    {
        private int _SoPhieu;
        private DateTime _NgayBan;
       
        private string _MaKhachHang;
        private string _NguoiBan;
        private decimal _TongTien;
        private decimal _TienNo;
        public int SoPhieu
        {
            get { return _SoPhieu; }
            set { _SoPhieu = value; }
        }
        public DateTime NgayBan
        {
            get { return _NgayBan; }
            set { _NgayBan = value; }
        }
        public string MaKhachHang
        {
            get { return _MaKhachHang; }
            set { _MaKhachHang = value; }
        }
        public string NguoiBan
        {
            get { return _NguoiBan; }
            set { _NguoiBan = value; }
        }
        public decimal TongTien
        {
            get { return _TongTien; }
            set { _TongTien = value; }
        }
        public decimal TienNo
        {
            get { return _TienNo; }
            set { _TienNo = value; }
        }
        public int LaySoHoaDon()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "select Max(SoPhieuBan) from PHIEUBANHANG";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
            OleDbDataReader r = cmd.ExecuteReader();
            int kq = 0;
            while (r.Read())
            {
                try
                {
                    kq = (int)r[0];
                }
                catch (Exception) { }
            }
            r.Close();
            connect.Close();
            return kq;
            
        }
        public void ThemHoaDon()
        {
            OleDbConnection connect = KetNoi.KetNoiDuLieu();
            string sql = "Insert into PHIEUBANHANG values(?,?,?,?,?,?)";
            OleDbCommand cmd = new OleDbCommand(sql, connect);
           /* cmd.Parameters.Add("@SoPhieuMua", OleDbType.Integer);
            cmd.Parameters.Add("@NgayMua", OleDbType.Date);
            cmd.Parameters.Add("@NgayThanhToan", OleDbType.Date);
            cmd.Parameters.Add("@MaKhachHang", OleDbType.VarChar);
            cmd.Parameters.Add("@TongTien", OleDbType.Decimal);
            cmd.Parameters.Add("@NguoiLapPhieu", OleDbType.VarWChar);*/
            cmd.Parameters.Add("@SoPhieuBan",OleDbType.Integer);
            cmd.Parameters.Add("@NgayBan",OleDbType.Date);
            cmd.Parameters.Add("@MaKhachHang",OleDbType.VarChar);
            cmd.Parameters.Add("@TongTien",OleDbType.Decimal);
            cmd.Parameters.Add("@TienNo",OleDbType.Decimal);
            cmd.Parameters.Add("@NguoiBan",OleDbType.VarWChar);
            
            cmd.Parameters[0].Value = SoPhieu;
            cmd.Parameters[1].Value = NgayBan;
            cmd.Parameters[2].Value = MaKhachHang;
            cmd.Parameters[3].Value = TongTien;
            cmd.Parameters[4].Value = TienNo;
            cmd.Parameters[5].Value = NguoiBan;
            cmd.ExecuteNonQuery();
            
        }

    }
}
